﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CanDoo;
using CanDoo.Core;
using CanDoo.Core.Data;
using CanDoo.Data;
using CanDoo.Extensions;
using CanDoo.Oil.Core.Contracts;
using CanDoo.Oil.Core.Models;
using CanDoo.Core.Dto;

namespace CanDoo.Oil.Core.Services
{
    /// <summary>
    /// 业务实现——商品
    /// </summary>
    public class ProductService : CanDoo.Data.Entity.Services.ServiceBase<Product>, IProductContract
    {
        public ProductService()
        {
        
        }
        /// <summary>
        /// 获取油品下拉列表数据
        /// </summary>
        /// <returns></returns>
        public IEnumerable<ListItem> GetSelectListByOil()
        {
            //if (SuportDictionaryEntity == false)
            //    throw new NotSupportedException();
            var rtn = Cacher.Get<IEnumerable<ListItem>>(nameof(GetSelectListByOil), () =>
            {
                using (DbScopeFactory.CreateReadOnly())
                {
                    return Entities.OrderBy(p => p.Code)
                    .Select(p=>new { p.Id,p.Code,p.ShortName}).ToArray()
                    .Select(p => new ListItem { Value = p.Id.ToString(), Text = $"[{p.Code}]{p.ShortName}", EnableSelect = true }).ToArray();
                }
            });
            return rtn;
        }
    }
}
